/** @file   temp_sensor.h
    @author M. P. Hayes, UCECE
    @date   6 Aug 2007
    @brief  Driver for ds18b20 temperature sensor.
*/

#ifndef TEMP_SENSOR_H
#define TEMP_SENSOR_H

#include "config.h"

typedef uint8_t temp_sensor_temp_t;


/** Scan for temperature sensor on the one wire bus.
    @return number of temperature sensors found or negative for error  */
extern int8_t
temp_sensor_init (void);


/** Start a temperature conversion.
    @param channel temperature sensor channel to start
    @return 1 if OK, 0 if no device responding, negative if error  */
extern int8_t
temp_sensor_start (uint8_t channel);


/** Read temperature value from selected channel.
    @param channel temperature sensor channel to read
    @param ptemp pointer to temperature to return
    @return 1 if OK, 0 if no device responding, negative if error
    @note This blocks until the temperature conversion has completed.
    @note \c temp_start () must have been previously called.  */
extern int8_t
temp_sensor_read (uint8_t channel, temp_sensor_temp_t *ptemp);


/** Read temperature value from selected channel.
    @param channel temperature sensor channel to read
    @param ptemp pointer to temperature to return
    @return 1 if OK, 0 if no device responding, negative if error
    @note This blocks until the temperature conversion has completed.
    @note This starts a new conversion and will keep looking for
    a temperature sensor.  */
extern int8_t
temp_sensor_get (uint8_t channel, temp_sensor_temp_t *ptemp);

#endif
